package zh.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zh.demo.dao.VcardColumnDao;
import zh.demo.dao.VcardDao;
import zh.demo.dao.VcardVisitDao;
import zh.demo.model.VcardEntity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("vcardService")
public class VcardService {
	@Autowired
	private VcardDao vcardDao;
	@Autowired
	private VcardColumnDao vcardColumnDao;
	@Autowired
	private VcardVisitDao vcardVisitDao;
	
	public VcardEntity queryObject(Long id){
		return vcardDao.queryObject(id);
	}
	
	public List<VcardEntity> queryList(Map<String, Object> map){
		return vcardDao.queryList(map);
	}
	
	public int queryTotal(Map<String, Object> map){
		return vcardDao.queryTotal(map);
	}
	
	public void save(VcardEntity vcard){
		vcardDao.save(vcard);
	}
	
	public void update(VcardEntity vcard){
		vcardDao.update(vcard);
	}
	
	public void delete(Long id){
		vcardDao.delete(id);
	}
	
	public void deleteBatch(Long[] ids){
		vcardDao.deleteBatch(ids);
	}

	public Map<String, Object> selectVcard(Long id, Long uid){
		Map<String, Object> map = new HashMap<>();
		map.put("id",id);
		map.put("uid",uid);
		VcardEntity vcardEntity = vcardDao.selectVCard(map);
		Long vcardId = vcardEntity.getId();
		List<Map<String, Object>> vcolumn = vcardColumnDao.selectColumnByVcardId(vcardId);
		List<Map<String, Object>> vvisit = vcardVisitDao.selectVisitByVcardId(vcardId);
		Map<String, Object> res = new HashMap<>();
		res.put("vard", vcardEntity);
		res.put("column", vcolumn);
		res.put("visit", vvisit);
		return res;
	}
	
}
